<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var minimumCardPickup = function (cards) {
      let ret = Infinity;
      let map = {};
      for (let i = 0; i < cards.length; i++) {
        if (map[cards[i]] !== void 0) {
          ret = Math.min(ret, i - map[cards[i]] + 1);
        }
        map[cards[i]] = i;
      }
      return ret == Infinity ? -1 : ret;
    };
    console.log(minimumCardPickup([3, 4, 2, 3, 4, 7]));
  </script>
</body>

</html>